ComponentManager
Manages components and lets you create components.
Functions
toComponent
sm.scrapcomputers.componentManager.toComponent( classData, componentType, isAComponent, automaticRefreshGen, isPowered, isInvisible )
Hooks your class so you can create components easly. For addon developers, this is required to be called on all of your components and interactables.
- For components: All variables must be used,
isAComponentwould be true. - For Interactables: Same for components but you can set componentType to nil and
isAComponentto false.
Arguments:
- classData [ ShapeClass ] The interactable's (or component) class.
- componentType [ string ] The type of component, Make sure this does not be a conflict with other addons or the mod itself!
- isAComponent [ boolean ] Set this to true if your interactable is a component!
- automaticRefreshGen [ boolean? ] If this is nil or true, It will generate onRefresh Functions. (Defaults to true)
- isPowered [ boolean? ] Whether the component supplies or recieves power via the power system or not.
- isInvisible [ boolean? ] If true, the component is hidden from computers (
sc.getComponents,sc.getAllComponents, etc.). Used for internal components like registers and antennas.
Registering the same class or component type twice is ignored.
For your component to behave as a generating component, the 'componentType' argument needs to be the string PowerComponents. If it is not a custom object, any other 'componentType' will result in a component that can only recieve power.
If you do not know how to use this function, this short guide will help you.
Add this:
-- For Components
sm.scrapcomputers.componentManager.toComponent( yourClass, "YourComponentType", true, false|true )
-- For Interactables
sm.scrapcomputers.componentManager.toComponent( yourClass, "YourComponentType", false, false|true )
-- DO NOT ADD ANY FURTHER CODE BELOW HERE!
getComponents
Use getComponentsSimplified instead.
sm.scrapcomputers.componentManager.getComponents( componentType, interactable, viaChildren, flags, getPrivateData )
Gets all connected components of the interactable and returns it.
Arguments:
- componentType [ string ] The component type to get.
- interactable [ Interactable ] The interactable to search through.
- viaChildren [ boolean ] If it should get components via children or parents.
- flags [ integer? ] The flags to use to get the components.
- getPrivateData [ boolean? ] Access private data for components (any data with
SC_PRIVATEat the start)
Returns:
- [ table ] All connected components it has discovered.
getComponentsSimplified
sm.scrapcomputers.componentManager.getComponentsSimplified( componentType, interactable, getPrivateData )
A simpler and safer replacement for getComponents. It automatically picks the correct direction (children or parents) and connection flags from how the component was registered.
Arguments:
- componentType [ string ] The component type to get.
- interactable [ Interactable ] The interactable to search through.
- getPrivateData [ boolean? ] If true, includes private data (any data with
SC_PRIVATEat the start).
Returns:
- [ table ] All connected components. Empty if the type isn't registered, isn't a component, or is invisible (unless
getPrivateDatais true).
getComponentTypes
sm.scrapcomputers.componentManager.getComponentTypes()
Returns all component type names. Component types that are invisible (registered with isInvisible set to true) are not included.
This is what computers get through sc.component.getComponentTypes.
This function was previously called getRegisteredComponentTypes and also returned invisible component types.
Returns:
- [ string[] ] The component types that are visible to computers.
isComponentTypeRegistered
sm.scrapcomputers.componentManager.isComponentTypeRegistered( componentType )
Checks if a component type is registered.
Arguments:
- componentType [ string ] The component type to check.
Returns:
- [ boolean ] If it is registered.
isComponentTypeAvaliable
sm.scrapcomputers.componentManager.isComponentTypeAvaliable( componentType )
Checks if a component type is registered and visible to computers (not invisible).
Arguments:
- componentType [ string ] The component type to check.
Returns:
- [ boolean ] If it is available.